﻿<?php

//downErWeiMa($_GET['starTime'],$_GET['endTime'],$_GET['shengFeng']);

ini_set("display_errors", "On");

downExcelAll();

function downExcelAll(){



	$qure='SELECT tell,CONCAT(shengFen,"|",city,"客户") AS dizhi,riqi FROM everydaytell  WHERE riqi BETWEEN "'.$_GET['starTime'].'" AND "'.$_GET['endTime'].'"';


	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);
	$arr=mysqli_fetch_all($result, 1);

	//var_dump($arr);

	require_once 'PHPExcel-1.8/Classes/PHPExcel.php';

	$excelFiled=array("客户名称/公司","联系人","联系方式","变量参数");

	//var_dump($excelFiled);

	$row=1;

	$objPHPExcel=new PHPExcel();

	$objPHPExcel->getActiveSheet()->fromArray($excelFiled,'A1');

	for($i=0;$i<count($arr);$i++){

		//$disCity=$arr['tell'][$i];

	 	$row+=1;

	 	$objPHPExcel->getActiveSheet()->setCellValue('A'.$row);

	 	$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,$arr[$i]['dizhi'].'|'.($row-1));

	 	$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $arr[$i]['tell']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, '');

	 	$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, '');


	}

		$objWriter =PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');

		$nameFile=date("Ymd").'D1';

		$objWriter->save("excel/{$nameFile}.xlsx");  // //excel/二维码.xlsx

//}


		header("Location: excel/{$nameFile}.xlsx");

}

?>